package com.allsheng.widget;

import com.allsheng.widget.AllShengDialog.ClickListenerInterface;
import com.example.allshengmedical.R;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

/**
 *	只能是运行结束的Dialog
 * @author Administrator
 *
 */

public class ShowFinishDialog extends AlertDialog {
	private Context context;
	private String rightText, leftText, closed;
	private View view;
	private MyClickListenerInterface clickListenerInterface;
	private TextView tvLeft, tvRight;
	TextView img_closed;
	boolean isBreak;

	/**
	 * @param title显示标题
	 * @param message显示内容
	 * @param rightText确定
	 */
	public ShowFinishDialog(Context context, String rightText) {
		super(context, R.style.dialog);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.rightText = rightText;

	}

	public ShowFinishDialog(Context context, String leftText, String rightText,
			String close, boolean isBreak) {
		super(context, R.style.dialog);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.rightText = rightText;
		this.leftText = leftText;
		this.isBreak = isBreak;
		this.closed = close;

	}

	public void setClicklistener(MyClickListenerInterface clickListenerInterface) {
		this.clickListenerInterface = clickListenerInterface;
	}

	public interface MyClickListenerInterface {
		public void Main();

		public void Dis();

		public void Anyalse();

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.pop_return_pop, null);
		setContentView(view);
		setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
		tvLeft = (TextView) view.findViewById(R.id.txt_returnmain);

		tvRight = (TextView) view.findViewById(R.id.txt_returnanylse);
		img_closed = (TextView) view.findViewById(R.id.pop_img_closed);
		view = view.findViewById(R.id.view);

		if (isBreak) {
			tvRight.setVisibility(View.GONE);
		} else {
			tvRight.setText(leftText);
			tvRight.setVisibility(View.VISIBLE);
		}
		tvLeft.setText(leftText);
		tvRight.setText(rightText);

		tvLeft.setOnClickListener(new clickListener());
		tvRight.setOnClickListener(new clickListener());
		img_closed.setOnClickListener(new clickListener());

		// Window dialogWindow = getWindow();
		// WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		// DisplayMetrics d = context.getResources().getDisplayMetrics();
		// lp.width = 480;
		// dialogWindow.setAttributes(lp);
	}

	private class clickListener implements View.OnClickListener {

		public void onClick(View v) {

			int id = v.getId();
			switch (id) {
			case R.id.txt_returnmain:
				clickListenerInterface.Main();
				break;
			case R.id.txt_returnanylse:
				clickListenerInterface.Anyalse();
				break;
			case R.id.pop_img_closed:
				clickListenerInterface.Dis();
				break;
			default:
				break;
			}
		}
	};
}
